package com.fast.configs;

import com.fast.configs.properties.AuthorizationProperties;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author ruan cai yuan
 * @version 1.0
 * @fileName com.fast.configs.WebMvcConfig
 * @description: TODO
 * @since 2024/6/22 2:39
 */
@Configuration
@EnableConfigurationProperties({AuthorizationProperties.class})
public class WebMvcConfig implements WebMvcConfigurer {

    /**
     * 定制化ObjectMapper
     */
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer objectMapperBuilderCustomizer() {
        return jacksonObjectMapperBuilder -> {
            // Long类型序列化为字符串,避免精度丢失
            jacksonObjectMapperBuilder.serializerByType(Long.class, ToStringSerializer.instance);
            //long类型序列化为字符串，避免精度丢失
            jacksonObjectMapperBuilder.serializerByType(Long.TYPE, ToStringSerializer.instance);
        };
    }
}
